Repository navigation
Add livetennisapi.reconcile for point gaps and score withdrawals - #8
Open
bensynapse wants to merge 1 commit into
Open
bensynapse wants to merge 1 commit into
bensynapse wants to merge 1 commit into
Conversation
The push feed already repairs point gaps inside PushStream. Anyone on the native /ws feed with their own socket, or taking webhooks, had to write that bookkeeping by hand, and score_withdrawn had no model. parse_frame() types a frame and raises FrameError on bad JSON. PointSequencer drops repeated point frames and holds frames that arrive after a missing seq. It reports the after_seq to fetch from get_match_points() and releases points in seq order once a page fills the gap. It refuses reconstruction pages, whose seq numbering differs. ScoreBook keeps the newest score per match by sequence. It drops a withdrawn or withheld state and flags a deferred one. No I/O and no new dependency. LiveScoreStream is unchanged.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
livetennisapi.reconcilefor people who read the Live Tennis API live feed on their own socket or through webhooks. It makes no network calls of its own.PushStreamalready repairs point gaps itself. The native/wsfeed and webhook receivers had nothing, andscore_withdrawnhad no model anywhere in the SDK.parse_frame(message)takes text, bytes or a dict and returns a typed frame:ScoreUpdate,PointUpdate, the newScoreWithdrawnandPointTagUpdate(point_update), the break-point pair, orControlFramefor anything else. Bad JSON, a non-object or a missingtyperaiseFrameError.PointSequencerdrops repeated point frames and holds frames that arrive after a missingseq.gap(match_id)gives theafter_seqto pass toget_match_points(), andfill()releases the held points inseqorder, each once. A page on thereconstructionbasis raisesValueError, because its numbering differs from the live stream.ScoreBookkeeps the newest score per match bysequence. Awithdrawnorwithheldframe drops the matching state and stops it coming back. Adeferredone keeps it and flags it throughverdict().The README has a new section with an asyncio example.
How I checked it:
pytest -m "not contract": 291 passed (45 of them new, intests/test_reconcile.py). They cover in-order, out-of-order and duplicate frames, a gap and its fill,score_withdrawnof each kind, and malformed input.ruff check src/ tests/andruff format --check src/are clean.mypy src/livetennisapireports nothing in the new module (the 8 errors it shows are already on main).scripts/truthcheck.shpasses.Not in this PR:
LiveScoreStreamstill dropsscore_withdrawnandpoint_updateframes without telling the caller, and the JS SDK has the same gap.